package com.baishancloud.log.analyzer

import scala.beans.BeanProperty

/**
 * 存放一些存储和计算使用的cass class
 *
 * @author ziqiang.wang 
 * @date 2021/11/10 15:21
 */
class Calculate extends Serializable


/**
 * 1小时统计一次，用户引擎聚合
 *
 * @param os       操作系统
 * @param device   设备名称
 * @param domain   域名id
 * @param time_at  统计开始时间
 * @param requests 请求次数
 * @param traffic  流量总额
 */
//----------user agent
case class UserAgent(@BeanProperty os: String, @BeanProperty device: String, @BeanProperty domain: Int, @BeanProperty time_at: String, @BeanProperty requests: Long, @BeanProperty traffic: Long) extends Serializable

object UserAgent extends Serializable {
  def apply(key: UserAgentKey, value: UserAgentValue): UserAgent = new UserAgent(key.osFamily, key.deviceFamily, key.domainId, key.timeAt, value.request, value.bytesSent)
}

case class UserAgentKey(osFamily: String, deviceFamily: String, domainId: Int, timeAt: String) extends Serializable

case class UserAgentValue(request: Long, bytesSent: Long) extends Serializable

/**
 * 5分钟统计一次，内容类型聚合
 *
 * @param media_type    媒体类型
 * @param domain        域名id
 * @param time_at       统计开始时间
 * @param requests      请求次数
 * @param traffic       请求流量总和
 * @param response_time 响应时间总和
 */
//----------content type
case class ContentType(@BeanProperty media_type: String, @BeanProperty domain: Int, @BeanProperty time_at: String, @BeanProperty requests: Long, @BeanProperty traffic: Long, @BeanProperty response_time: Long) extends Serializable

object ContentType extends Serializable {
  def apply(key: ContentTypeKey, value: ContentTypeValue): ContentType = new ContentType(key.strMediaType, key.domainId, key.timeAt, value.requests, value.bytesSent, value.responseTime)
}

case class ContentTypeKey(strMediaType: String, domainId: Int, timeAt: String) extends Serializable

case class ContentTypeValue(requests: Long, bytesSent: Long, responseTime: Long) extends Serializable


/**
 * 5分钟一统计，域名目录聚合
 *
 * @param domain    域名id
 * @param directory 目录
 * @param time_at   统计开始时间
 * @param traffic   请求流量总和
 */
//----------directory
case class DomainDirectory(@BeanProperty domain: Int, @BeanProperty directory: String, @BeanProperty time_at: String, @BeanProperty traffic: Long) extends Serializable

object DomainDirectory extends Serializable {
  def apply(key: DomainDirectoryKey, value: DomainDirectoryValue): DomainDirectory = new DomainDirectory(key.domainId, key.directory, key.timeAt: String, value.bytesSent)
}

case class DomainDirectoryKey(domainId: Int, directory: String, timeAt: String) extends Serializable

case class DomainDirectoryValue(bytesSent: Long) extends Serializable
